/*
 * @Author: your name
 * @Date: 2021-03-24 22:23:36
 * @LastEditTime: 2021-04-27 23:06:08
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \jianfa-api\dao\stateDao.js
 */
const { querySql } = require("../db");
const { page_sql } = require("../utils/utils");
const moment = require("moment");
moment.locale("zh-cn");
module.exports = {
    // 增加二级父菜单
    async addTowListDao({ class_name }) {
        // moment().format('MM月D日')
        const sql = `insert into state_tow_list (class_name , sort) values ('${class_name}',${Date.now()})`;
        return await querySql(sql);
    },
    // 获取二级父菜单
    async getTowListDao() {
        // moment().format('MM月D日')
        const sql = `select * from state_tow_list`;
        return await querySql(sql);
    },
    // 删除二级父菜单
    async delTowListDao({ id }) {
        // moment().format('MM月D日')
        const sql = `delete from state_tow_list where id='${id}'`;
        return await querySql(sql);
    },
    // 增加实时列表
    async addListDao({ class_name, id }) {
        // moment().format('MM月D日')
        const sql = `insert into state_list (tid , class_name , sort) values ('${id}','${class_name}','${Date.now()}')`;
        return await querySql(sql);
    },
    //添加网站链接
    async addWebUrlDao({ cid, url }) {
        // moment().format('MM月D日')
        const sql = `insert into state_url (cid , url , create_time) values ('${cid}','${url}','${moment().format(
            "YY年MM月D日hh时mm分"
        )}')`;
        return await querySql(sql);
    },
    //获取列表
    async getListDao({ id }) {
        // moment().format('MM月D日')
        const sql = `select * from state_list where tid=${id}`;
        return await querySql(sql);
    },
    //获取网站链接
    async getUrlDao(params) {
        const { id } = params;
        const sql = `select id,url,create_time from state_url where cid='${id}'`;
        return await querySql(await page_sql(params, sql, "state_url"));
    },

    async delListDao({ id }) {
        const sql = `delete from state_list where id='${id}'`;
        return await querySql(sql);
    },

    async delUrlDao({ id }) {
        const sql = `delete from state_url where id='${id}'`;
        return await querySql(sql);
    },
};
